<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<p><img src="./on.gif" id="on" onclick="attr('src','./off.gif')"/></p>
<script>
        document.querySelector("img").onclick = function(){
            //1.获取src的值

            //2.判断是不是on.gif 如果是就改成off.gif
            if(this.src.indexOf('on.gif') != -1){
                this.src = 'img/off.gif'
            }else{
                this.src = 'img/on.gif'
            }

            //3.如果是off.gif,就改成on.gif
        };
</script>
</body>
</html>